const { Model, DataTypes } = require("sequelize");
const sequelize = require("../sequelize.js");

/**
 * 账户信息
 */
class Users extends Model {
  static init() {
    super.init(
      {
        id: {
          type: DataTypes.INTEGER,
          autoIncrement: true,
          primaryKey: true,
        },
        account: {
          type: DataTypes.STRING(32),
        },
        password: {
          type: DataTypes.STRING(64),
        },
        salt: {
          type: DataTypes.STRING(8),
        },
        permission: {
          type: DataTypes.INTEGER,
        },
        openid: {
          type: DataTypes.STRING(128),
        },
        nickname: {
          type: DataTypes.STRING(32),
        },
        avatar_url: {
          type: DataTypes.STRING(255),
        },
        gender: {
          type: DataTypes.INTEGER,
        },
        birthday: {
          type: DataTypes.DATE,
        },
        phone: {
          type: DataTypes.STRING(16),
        },
        email: {
          type: DataTypes.STRING(128),
        },
        status: {
          type: DataTypes.INTEGER,
        },
        created_at: {
          type: DataTypes.DATE,
        },
        updated_at: {
          type: DataTypes.DATE,
        },
      },
      {
        sequelize,
        tableName: "users",
        createdAt: "created_at",
        updatedAt: "updated_at",
      }
    );
    return this;
  }
}

Users.init();

module.exports = Users;
